/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean;

import com.jb.framework.PersistentContext;
import com.jb.web.context.WebContext;


/**
 * A simple container to hold other components.
 */
public class Panel extends Region {
    static final long serialVersionUID = 123123L;
    private static String DRAG_DROP="Drag & Drop";
    static {
        publish(Panel.class, DATA, "value");
        publish(Panel.class, DRAG_DROP, "droppable");
        publish(Panel.class, DRAG_DROP, "onDraggedOn"); //when an element dragged on to this one
        publish(Panel.class, DRAG_DROP, "onDragging"); //when an element dragged on to this one
        publish(Panel.class, DRAG_DROP, "onDraggedOut"); //when an element dragged out of this one
        publish(Panel.class, DRAG_DROP, "onDroppedOn"); //when an element dropped on this one
    }
    
    private boolean droppable=false;
    private boolean showHeader;
    private String onDraggedOn;
    private String onDraggedOut;
    private String onDroppedOn;
    private String onDragging;

    public void setDefault(PersistentContext pCtx) {
        super.setDefault(pCtx);
        setHeight("300px");
        this.setStyleClass("jbPanel");
        setValue("Panel");
    }
    public void updateView(WebContext ctx) {
        if(droppable) {
            ctx.addDroppable(this.getClientId());
        }
        super.updateView(ctx);
    }

    public void setOnDraggedOn(String onDraggedOn) {
        this.onDraggedOn = onDraggedOn;
    }

    public String getOnDraggedOn() {
        return onDraggedOn;
    }

    public void setOnDraggedOut(String onDraggedOut) {
        this.onDraggedOut = onDraggedOut;
    }

    public String getOnDraggedOut() {
        return onDraggedOut;
    }

    public void setOnDroppedOn(String onDroppedOn) {
        this.onDroppedOn = onDroppedOn;
    }

    public String getOnDroppedOn() {
        return onDroppedOn;
    }
    /**
     * Setter for property showHeader.
     *
     * @param showHeader New value of property showHeader.
     */
    public void setShowHeader(boolean showHeader) {
        this.showHeader = showHeader;
    }

    /**
     * Getter for property showHeader.
     *
     * @return Value of property showHeader.
     */
    public boolean isShowHeader() {
        return showHeader;
    }

    public boolean isVisible(WebContext pCtx) {
        if (this.getParent() instanceof TabbedPanel) {
            TabbedPanel p = (TabbedPanel) this.getParent();

            if (p.getSelected() != this) {
                return false;
            }
        }

        return super.isVisible(pCtx);
    }


    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String toString() {
        return "Panel " + getSequence();
    }


    public void setDroppable(boolean param) {
        this.droppable = param;
    }

    public boolean isDroppable() {
        return droppable;
    }

    public void setOnDragging(String param) {
        this.onDragging = param;
    }

    public String getOnDragging() {
        return onDragging;
    }
}
